<?php
	$boss_obj = new boss();
	
	//action对应表
	$action_ary = array(	
	  'login'=>'boss_act_login',
	  'quit'=>'boss_act_quit',
	  'edit' =>'boss_act_edit',
	  'pwd'  =>'boss_act_update_pwd',
	  'bind' =>'boss_act_bind',
	  'cash' =>'boss_act_cash',
	  'delcash'=>'boss_act_delcash',
	  'admin_edit'=>'admin_act_boss_edit',
	  'boss_unique'=>'admin_act_boss_unique',
	  'admin_carstate'=>'admin_act_carstate',
	  'boss_cashdeal'=>'admin_act_boss_cashdeal',
	  'boss_cashdel'=>'admin_act_boss_cashdel',
	  'boss_cashadd'=>'admin_act_boss_cashadd',
	  'boss_report'=>'admin_act_boss_report',
	  'boss_report_record'=>'admin_act_boss_report_record',
	  'boss_report_car'=>'admin_act_boss_report_car',
	  'boss_report_dust'=>'admin_act_boss_report_dust',
	  'boss_report_dust_all'=>'admin_act_boss_report_dust_all'
	);

	//执行函数
	if($action && ($fun = $action_ary[$action])){
		$fun();		
	}
		
	//action
	//*+------------------------------------------------------------------------+*/		
		
	/**
	 * 登陆
	 * @author leiqianyong 2016-12-24 10:38 AM 
	 */
	function boss_act_login(){
		global $boss_obj;
	
		$rtn=array('state'=>false);
	
		//管理员登陆账号
		$account = trim(request('account'));
		//管理员登陆密码
		$password = trim(request('password'));
	
		//验证码
		/**
		$code = request('code');
		if(!$code){
			$rtn['msg']='请输入验证码';
			echo json_encode($rtn);exit;
		}
	
		//验证码输入错误
		$auth_code_object = new auth_code();
		if(!$auth_code_object->check($code)){
			$rtn['msg']='验证码错误';
			echo json_encode($rtn);exit;
		}
		**/
	
		//账户为空  或者密码为空
		if(is_null_str($account) || is_null_str($password)){
			$rtn['msg']='请输入账号和密码';
			exit(json_encode($rtn));
		}
	
		// 用户名 或密码输入错误
		if(!$row = $boss_obj->_login($account, $password)){
			$rtn['msg']='账号或密码不正确';
			exit(json_encode($rtn));
		}
	
		//判定账户是否处于锁定状态
		if($row['state']!=1){
			$rtn['msg']='账户已被锁定';
		    exit(json_encode($rtn));
		}
	
		//存一个管理员账号cookie
		set_cookie('b_account',$account);
	
		$rtn['state'] = true;
		$rtn['msg']='登录成功';
		$rtn['url']='/boss/center';
		exit(json_encode($rtn));
	}	
	
	
	//确认充值信息
	function admin_act_boss_cashdeal(){
		global $boss_obj;
		
		$admin_obj=new admin();
		$user_info = $admin_obj->out_cookie();
		if(empty($user_info)){
			location_msg('管理员请登录');
		}

		$id=request('id',false,true);
		
		$cinfo=$boss_obj->cash_info($id);
		if(empty($cinfo)){
			location_msg('充值记录不存在');
		}
		
		if($cinfo['state']==1){
			location_msg('该记录已处理');
		}
		
		$comment=request('comment');
		if(!$comment){
			location_msg('请添加备注信息');
		}
		
		if(!$cinfo['carid'] || !$cinfo['length']){
			location_msg('参数不正确');
		}
		
		//处理时间
		$cid=$cinfo['carid'];
		$time=$cinfo['length'];
		if($boss_obj->cash_add_time($cid, $time)){
		   $data['state']=1;
		   $data['comment']=$comment;
		   $boss_obj->cash_edit($id, $data);
		   location_msg('充值成功');
		}
				
		location_msg('充值失败');
	}
	
	
	//后台直接充值
	function admin_act_boss_cashadd(){
		global $boss_obj;
		
		$admin_obj=new admin();
		$user_info = $admin_obj->out_cookie();
		if(empty($user_info)){
			location_msg('管理员请登录');
		}
		
		$id=request('id',false,true);
		
		$cinfo=$boss_obj->_car_info($id);
		if(empty($cinfo)){
			location_msg('设备不存在');
		}
		
		$comment=request('comment');
		if(!$comment){
			location_msg('请添加备注信息');
		}		
		
		$pid=request('pid',false,true,false,0);		
		$crty=cash_menu();
		
		$cash=$crty[$pid];
		if(empty($cash)){
			location_msg('套餐信息不存在');
		}
				
		//处理时间		
		$time=$cash['time'];		
		if($boss_obj->cash_add_time($id, $time)){
		   $data['state']=1;
		   $data['uid']=$cinfo['uid'];
		   $data['carid']=$cinfo['id'];
		   $data['length']=$time;
		   $data['time']=time();
		   $data['money']=$cash['money'];
		   $data['comment']=$comment;
		   $boss_obj->cash_add($data);
		   location_msg('充值成功');
		}
				
		location_msg('充值失败');	
	}
	
	
	
	//删除充值信息
	function admin_act_boss_cashdel(){
		global $boss_obj;
		
		$admin_obj=new admin();
		$user_info = $admin_obj->out_cookie();
		if(empty($user_info)){
			location_msg('管理员请登录');
		}
		
		$id=request('id',false,true);
		
		$cinfo=$boss_obj->cash_info($id);
		if(empty($cinfo)){
			location_msg('充值记录不存在');
		}
		
		if($cinfo['state']==1){
			location_msg('该记录已处理');
		}		
		
		if($boss_obj->cash_del($id)){
			location_msg('删除成功');
		}
		
		location_msg('删除失败');
	}
	
	
	/**
	 * 管理员修改账号
	 * @author leiqianyong 2016-12-20 13:48 PM
	 */
	function boss_act_edit() {
		global $boss_obj;
	
		$rtn=array('state'=>false);
	
		//验证是否登录
		$aid=is_cookie_login('boss');
		if(!$aid){
			$rtn['msg']='请登录';
			exit(json_encode($rtn));
		}
	
		$name=request('name');
		if(!$name){
			$rtn['msg']='请输入姓名';
			exit(json_encode($rtn));
		}
	
		if(strlen($name)>30){
			$rtn['msg']='姓名输入过长';
			exit(json_encode($rtn));
		}
	
		//电话号码
		$phone=request('phone');
		if(!is_mobile($phone)){
			$rtn['msg']='请输入手机号码';
			exit(json_encode($rtn));
		}
	
		//邮箱
		$email=request('email',false,false,true);
		if(!$email){
			$rtn['msg']='请输入邮箱号码';
			exit(json_encode($rtn));
		}
	
		$sex=request('sex',false,true,false,1);
		$data=compact('name','phone','email','sex');
	
		$res=$boss_obj->_update_boss($aid, $data);
			
		if(!$res){
			$rtn['msg']='修改失败';
			exit(json_encode($rtn));
		}
	
		$rtn['msg']='修改成功';
		$rtn['state']=true;
		$rtn['url']='/boss/center';
		exit(json_encode($rtn));
	}
	
	
	/**
	 * 管理员添加修改账号信息
	 * @author leiqianyong 2016-12-28 9:41 AM 
	 */
	function admin_act_boss_edit(){
		global $boss_obj;
		
		$id=request('id',false,true,false,0);

		//添加时检测账号，密码
		if(!$id){
			//添加的账户
			$account = request('account');
			if(!$account){
				location_msg('请输入账号');
			}
			
			//查询添加账户是否存在
			if($boss_obj->unique_boss($account)){
				location_msg('账号已存在');
			}			
			
			//添加的密码 md5 加密
			$password = request('password');
			$repassword = request('repassword');
		
			if(!$password){
				location_msg('请输入密码');
			}
			if($password != $repassword){
				location_msg('两次密码不正确');
			}
			$password = md5($password);			
		}
		
		//添加的姓名
		$name = request('name');
		//添加的电话
		$phone = request('phone');
		//判断电话是否正确
		if($phone && !is_mobile($phone)){
			location_msg('请输入正确的手机号码');
		}		
		
		//添加的状态,默认为开启
		$state = request('state', false, true, false, 1);
		//添加的性别
		$sex = request('sex', false, true);
		$email = request('email', false, false,true);
		
		if(!$id){
			$time = time();
			$data = compact('account','password','name','phone','state','sex','time','email');

			if(!$aid=$boss_obj->_add_boss($data)){
				location_msg('添加失败');
			}
			
			$jump_url=request('jump_url')?request('jump_url'):'/admin/boss_account';
			location_msg('添加成功', $jump_url);				
		}
		
		$data=compact('name','phone','state','sex','email');
		
		$password = request('password');				
		if($password){
			$repassword = request('repassword');
			if($password != $repassword){
				location_msg('两次密码不正确');
			}
				
		    $data['password']=md5($password);	
		}
			
		if(!$boss_obj->_update_boss($id,$data)){
			location_msg('修改失败');
		}
			
		$jump_url=request('jump_url')?request('jump_url'):'/admin/boss_account';
		location_msg('修改成功', $jump_url);
		
	}
	
	
	//帐号唯一性检测
	function admin_act_boss_unique(){
		global $boss_obj;
		$account = request('param');
		$s = $boss_obj->unique_boss($account);
		if($s){
			echo '该帐号已存在';
			exit;
		}else{
			echo 'y';
			exit;
		}
	}	
	
	
	//修改车辆型号
	function admin_act_carstate(){
		global $boss_obj;
		
		$admin_obj=new admin();
		$user_info = $admin_obj->out_cookie();
		if(empty($user_info)){
			location_msg('管理员请登录');
		}		
		
		$id=request('id',false,true);
		if(!$id){
			location_msg('修改失败');
		}
		
		$state=request('state',false,true,false,0);
		$state=(1==$state)?1:0;
		
		$data['state']=$state;
		if($boss_obj->_update_car($id, $data)){
			location_msg('修改成功');
		}
		
		location_msg('修改失败');
	}
	
	 
	/**
	 * 修改密码
	 *
	 * @author limin 2012-8-21 PM 14:46:05
	 */
	function boss_act_update_pwd() {
		global $boss_obj;
	
		$rtn=array('state'=>false);
	
		//验证是否登录
		$aid=is_cookie_login('boss');
		if(!$aid){
			$rtn['msg']='请登录';
			exit(json_encode($rtn));
		}
	
		//原始密码
		$oldpwd = request('oldpwd');
		if(!$oldpwd){
			$rtn['msg']='请输入旧密码';
			exit(json_encode($rtn));
		}
		 
		$admininfo=$boss_obj->boss_info('password');
		if($admininfo['password']!=md5($oldpwd)){
			$rtn['msg']='旧密码不正确';
			exit(json_encode($rtn));
		}
	
		//新密码
		$password = request('newpwd');
		if(!$password){
			$rtn['msg']='请输入新密码';
			exit(json_encode($rtn));
		}
	
		//确认密码
		$repwd = request('repwd');
		if($repwd!=$password){
			$rtn['msg']='确认码不正确';
			exit(json_encode($rtn));
		}
		 
		$data['password']=md5($repwd);
		$res=$boss_obj->_update_boss($aid, $data);
		if(!$res){
			$rtn['msg']='操作失败';
			exit(json_encode($rtn));
		}
	
		$rtn['msg']='操作成功';
		$rtn['state']=true;
		exit(json_encode($rtn));
	}	
	
	
	/**
	* 注销用户,退出登录
	* @author leiqianyong 2016-12-24 10:35 AM 	
	*/
	function boss_act_quit(){									
		del_cookie('boss');
		del_cookie('boss_info');
		header('location: /boss/login');exit();		
	}

	
	
	/**
	 * 绑定挖机
	 * @author leiqianyong 2016-12-24 15:27 PM 
	 */
	function boss_act_bind(){
		global $boss_obj;
		
		$rtn=array('state'=>false);
		
		//验证是否登录
		$aid=is_cookie_login('boss');
		if(!$aid){
			$rtn['msg']='请登录';
			exit(json_encode($rtn));
		}

		$id=request('id',false,true,false,false,0);
		
		//车辆型号
		$car = trim(request('car'));
		if(!$car){
			$rtn['msg']='请输入车辆型号';
			exit(json_encode($rtn));
		}		
		
		//车牌号
		$carno = trim(request('carno'));
		if(!$carno){
			$rtn['msg']='请输入车牌号';
			exit(json_encode($rtn));
		}	
		//检查车牌号在当前老板的序列中是否已经存在
		$carno_exist=$boss_obj->_car_carno_unique($carno,$aid,'id,carno');
		if($carno_exist){
			if(!$id){
				$rtn['msg']='车牌号已存在';
				exit(json_encode($rtn));				
			}
			
			if($id && $carno_exist['id']!=$id){
				$rtn['msg']='车牌号已存在';
				exit(json_encode($rtn));				
			}
		}
		
							
		//车辆司机
		$linkman = trim(request('linkman'));
		if($linkman && strlen($linkman)>10){
			$rtn['msg']='司机姓名太长';
			exit(json_encode($rtn));
		}
		
		//电话号码
		$phone= trim(request('phone'));
		if($phone && !is_mobile($phone)){
			$rtn['msg']='请输入手机号码';
			exit(json_encode($rtn));
		}
			
		$data=compact('car','carno','linkman','phone','code');		
		
		//设备号
		$code= trim(request('code'));
		if($code){
			if(strlen($code)>30){
				$rtn['msg']='设备号输入不正确';
				exit(json_encode($rtn));
			}

			//检查设备号信息
			$_code=$boss_obj->_device_info($code);
			if($_code['state']==-1){
				$rtn['msg']='设备号不存在';
				exit(json_encode($rtn));				
			}
			
			$data['codeid']=$_code['id'];
			$data['code']=$code;
			$data['bindtime']=time();			

			if($_code['state']==-2){
				if(!$id){
				   $msg=$_code['uid']==$aid?'您已绑定过该设备':'该设备已被绑定';	
				   $rtn['msg']=$msg;
				   exit(json_encode($rtn));
				}
				
				if($id && $_code['bid']!=$id){
				   $msg=$_code['uid']==$aid?'您已绑定过该设备':'该设备已被绑定';	
				   $rtn['msg']=$msg;
				   exit(json_encode($rtn));
				}	

				if($id && $_code['bid']==$id){
					unset($data['codeid'],$data['code'],$data['bindtime']);
				}
			}	

		}else{
			$data['codeid']=0;
			$data['code']='';
			$data['bindtime']=0;
		}
							
		//添加操作
		if(!$id){
			$data['uid']=$aid;
			$data['endtime']=time();
			$res=$boss_obj->_add_car($data);
			if(!$res){
				$rtn['msg']='添加失败';
				exit(json_encode($rtn));
			}			
						
			$rtn['msg']='添加成功';
			$rtn['state']=true;
			exit(json_encode($rtn));						
		}
				
		//修改
		$res=$boss_obj->_update_car($id, $data);
		if(!$res){
			$rtn['msg']='修改失败';
			exit(json_encode($rtn));
		}
		
		$rtn['msg']='修改成功';
		$rtn['state']=true;
		exit(json_encode($rtn));				
	}


	//提交充值信息
	function boss_act_cash(){
		global $boss_obj;
		
		$rtn=array('state'=>false);
		
		//验证是否登录
		$aid=is_cookie_login('boss');
		if(!$aid){
			$rtn['msg']='请登录';
			exit(json_encode($rtn));
		}

		//充值账号id
	    $did=request('did',false,true);
	    if(!$did){
	    	$rtn['msg']='缺少车辆参数';
	    	exit(json_encode($rtn));	    	
	    }
	    
	    $prtn=cash_menu();
	    
	    //套餐类型
	    $type=request('ptype',false,true,false,2);
	    if(!$type || !$prtn[$type]){
	    	$rtn['msg']='套餐参数不正确';
	    	exit(json_encode($rtn));	    	
	    }
	    
	    $data['uid']=$aid;
	    $data['carid']=$did;
	    $data['length']=$prtn[$type]['time'];
	    $data['money']=$prtn[$type]['money'];
	    $data['time']=time();
	    
	    $res=$boss_obj->cash_add($data);
	    if(!$res){
	    	$rtn['msg']='提交失败';
	    	exit(json_encode($rtn));	    	
	    }
	    
	    $rtn['msg']='提交成功';
	    $rtn['state']=true;
	    exit(json_encode($rtn));	    
	}
		
	//删除充值申请
	function boss_act_delcash(){
		global $boss_obj;
		
		$rtn=array('state'=>false);
		
		//验证是否登录
		$aid=is_cookie_login('boss');
		if(!$aid){
			$rtn['msg']='请登录';
			exit(json_encode($rtn));
		}

		//技术
		$id=request('id',false,true);
		if(!$id){
			$rtn['msg']='缺少参数';
			exit(json_encode($rtn));			
		}
		
		$res=$boss_obj->cash_del($id,$aid);
		
		if(!$res){
			$rtn['msg']='删除失败';
			exit(json_encode($rtn));			
		}
		
		$rtn['msg']='删除成功';
		$rtn['state']=true;
		exit(json_encode($rtn));		
	}
	
	
	//挖机装车明细
	function admin_act_boss_report(){		
		global $boss_obj;
				
		$data = $_GET;
		
		$starttime=strtotime(request('start_time'));
		$endtime=strtotime(request('end_time'));
		if($endtime<$starttime){
			location_msgwap('起止时间不正确');
		}	

		if(($endtime+86400-$starttime)/86400>10){
			location_msgwap('起止时间不能超过10天');
		}		
		
		//1装车
		$type=request('type',false,true,false,1);
		$cols='id,pid,ctime,dname,dno,truck,dust';
		$list=$boss_obj->get_report_all($data,$type);
		if(empty($list)){
			location_msgwap("暂无数据");
		}
		
		$filename = "SYT_REPORT:".date('YmdHis') ;		
		$title_ext = '挖机装车明细统计' ;			
		$title = array('项目名称','挖机编号','设备号','登记时间','装车时间','渣车类型','土石类型');
		
		$cols_num = count($title);
		$html='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
	    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	    <html>
	    <head>
	    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
	    </head>
	    <body>
	    <table x:str border=1 cellpadding=0 cellspacing=0>';
		
		$html .= '<tr><td width=”100″ colspan='.$cols_num.' align=center style=\'font-size:14.0pt;font-weight:700;font-family:"Arial Unicode MS", sans-serif;height:25pt\'>'.$title_ext.'</td></tr>';
		
		//开始时间
		if($data['start_time'] || $data['end_time']){
			$_num=count($list);
			$html .= "<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;统计期间：{$data['start_time']} ~ {$data['end_time']}&nbsp;&nbsp;&nbsp;&nbsp;共计{$_num}车</td></tr>";
		}
		
		//导出xls 开始
		if (!empty($title)){
			$html .= '<tr>' ;
			foreach ($title as $k => $v) {
				$html .= '<td width=”100″ align=center style=\'height:25pt;background:silver;\'>'.$v.'</td>' ;
			}
			$html .= '</tr>' ;
		}
		
		//项目名称
		$project_obj=new project();
		$project_ary=$project_obj->project_all();
		
		$type_ary=array(1=>'装车',2=>'计时',3=>'渣车');
		$state_ary=array(1=>'有效',0=>'无效');		
		$dust_ary=array(1=>'Ⅰ',2=>'Ⅱ',3=>'Ⅲ');
		
		if(!empty($list)){
			$_header=0;
			$length=0;
			foreach($list as $key=>$cv){
				if($_header){
					$length=$cv['ctime']-$_header;
				}
				$_header=$cv['ctime'];
				$dis_time=($length>900||$length<=0)?'360':$length;
				$dis_timestr=timeparsesecond($dis_time);
	
				$html .= '<tr>' ;
				$html .= '<td width=”100″ align=right x:str>'.($project_ary[$cv['pid']]).'</td>' ;					
				$html .= '<td width=”100″ align=center x:str><strong>'.($cv['dname']).'</strong></td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($cv['dno']).'</td>' ;
				$html .= '<td width=”100″ align=center x:str>'.(date('YmdHis',$cv['ctime'])).'</td>' ;
				$html .= '<td width=”100″ align=center x:num>'.($dis_timestr).'</td>' ;					
				$html .= '<td width=”100″ align=center x:str>'.(strtoupper($cv['truck'])).'</td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($dust_ary[$cv['dust']]).'</td>' ;										
				$html .= '</tr>' ;
			}
		}
		
		
		$html .= '</table></body></html>';
				
		header("Content-type:application/vnd.ms-excel");
		header('Content-Type: application/octet-stream');
		header("Content-Disposition:attachment;filename={$filename}.xls");
		header('Cache-Control: max-age=0');
		exit($html);		
	}
	
	
	//装车数量统计
	function admin_act_boss_report_record(){
		global $boss_obj;
	
		$data = $_GET;
		$data['end_time']=$data['start_time'];
						
		$list=$boss_obj->get_report_total($data);
		if(empty($list)){
			location_msgwap("暂无数据");
		}
			    	
		$filename = "SYT_REPORT:".date('YmdHis') ;
		$title_ext = '装车数量统计' ;
		$title = array('渣车类型','土石类型','数量');
	
		$cols_num = count($title);
		$html='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
	    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	    <html>
	    <head>
	    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
	    </head>
	    <body>
	    <table x:str border=1 cellpadding=0 cellspacing=0>';
	
		$html .= '<tr><td width=”100″ colspan='.$cols_num.' align=center style=\'font-size:14.0pt;font-weight:700;font-family:"Arial Unicode MS", sans-serif;height:25pt\'>'.$title_ext.'</td></tr>';
	
		//开始时间
		if($data['start_time']){			
			$html .= "<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;统计期间：{$data['start_time']} </td></tr>";
		}
	
		//导出xls 开始
		if (!empty($title)){
			$html .= '<tr>' ;
			foreach ($title as $k => $v) {
				$html .= '<td width=”100″ align=center style=\'height:25pt;background:silver;\'>'.$v.'</td>' ;
			}
			$html .= '</tr>' ;
		}

		$truck_rtn=array('a'=>'A型车','b'=>'B型车','c'=>'C型车');		
		$dust_ary=array(1=>'Ⅰ 类料',2=>'Ⅱ 类料',3=>'Ⅲ 类料');
		$_num=0;
		if(!empty($list)){
			foreach($list as $val){
				$rtn[$val['truck']][$val['dust']]=$val['num'];
			}
						
			foreach($truck_rtn as $k=>$v){
				foreach ($dust_ary as $key=>$vo){
				$_num+=$rtn[$k][$key]?$rtn[$k][$key]:0;			
				$html .= '<tr>' ;
				if($key==1)
				$html .= '<td width=”100″ rowspan="3" align=right x:str>'.($v).'</td>' ;
				$html .= '<td width=”100″ align=center x:str><strong>'.($vo).'</strong></td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($rtn[$k][$key]).'</td>' ;				
				$html .= '</tr>' ;
				}
			}
		}
	
		$html .= "<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;合计：{$_num} 车</td></tr>";
		
		$html .= '</table></body></html>';
				
		header("Content-type:application/vnd.ms-excel");
		header('Content-Type: application/octet-stream');
		header("Content-Disposition:attachment;filename={$filename}.xls");
		header('Cache-Control: max-age=0');
		exit($html);	
	}	
	

	//挖机工作时间统计
	function admin_act_boss_report_car(){
		global $boss_obj;
		
		$data = $_GET;
		
		$did=request('did',false,true);
		if(!$did){
			location_msgwap('设备信息不存在');
		}
		$data['end_time']=$data['start_time'];
		//检查设备今天的数据类型  1,2挖机  3-渣车
		$type=$boss_obj->get_report_type($data);		
		if($type==3){
			admin_act_boss_report_dustcar($data);
			exit();
		} 
		if(empty($type)){
			location_msgwap("暂无数据");
		}
								
		$list=$boss_obj->get_report_car($data);
		$list_time=$boss_obj->get_report_car_time($data);
		if(empty($list) && empty($list_time)){
			location_msgwap("暂无数据");
		}
		
		$cid=request('cid',false,true);
		$dinfo=$boss_obj->_car_info($cid,'code,carno');		
		
		$filename = "SYT_REPORT:".date('YmdHis') ;
		$title_ext = '挖机工作时间统计表' ;
		$title = array('类型','时间','');
		
		$cols_num = count($title);
		$html='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
	    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	    <html>
	    <head>
	    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
	    </head>
	    <body>
	    <table x:str border=1 cellpadding=0 cellspacing=0>';
		
		$html .= '<tr><td width=”100″ colspan='.$cols_num.' align=center style=\'font-size:14.0pt;font-weight:700;font-family:"Arial Unicode MS", sans-serif;height:25pt\'>'.$title_ext.'</td></tr>';
		
		//开始时间
		if($data['start_time']){
			$html .= "<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;统计期间：{$data['start_time']}&nbsp;&nbsp;&nbsp;&nbsp;挖机编号：{$dinfo['carno']}&nbsp;&nbsp;&nbsp;&nbsp;设备号：{$dinfo['code']}</td></tr>";
		}
		
		//导出xls 开始
		if (!empty($title)){
			$html .= '<tr>' ;
			foreach ($title as $k => $v) {
				$html .= '<td width=”100″ align=center style=\'height:25pt;background:silver;\'>'.$v.'</td>' ;
			}
			$html .= '</tr>' ;
		}
		
		
		$_listtime='';
		$_sumtime=0;
		if($list){
			$length=0;
			foreach($list as $key=>$cv){
				if($_header){
					$length=$cv['ctime']-$_header;
				}
				$_header=$cv['ctime'];
				$dis_time+=($length>900||$length<=0)?'360':$length;
			}
			$_sumtime=$dis_time;
			$_listtime=timeparsesecond($dis_time);
		}
					
		$html .= '<tr>' ;		
		$html .= '<td width=”100″ align=center x:str><strong>装车时间</strong></td>' ;
		$html .= '<td width=”100″ align=center x:str>'.($_listtime).'</td>' ;
		$html .= '</tr>' ;		
		
		$_listtime='';
		if($list_time){
			$length=0;
			foreach($list_time as $val){
				$length+=($val['num']-1)*180;
			}
			$_sumtime+=$length;
			$_listtime=timeparsesecond($length);
		}
		
		$html .= '<tr>' ;
		$html .= '<td width=”100″ align=center x:str><strong>辅助时间</strong></td>' ;
		$html .= '<td width=”100″ align=center x:str>'.($_listtime).'</td>' ;
		$html .= '</tr>' ;	

		$html .= '<tr>' ;
		$html .= '<td width=”100″ align=center x:str><strong>合计时间</strong></td>' ;
		$html .= '<td width=”100″ align=center x:str>'.(timeparsesecond($_sumtime)).'</td>' ;
		$html .= '</tr>' ;

				
		$list=$boss_obj->get_report_total($data);
		
		$truck_rtn=array('a'=>'A型车','b'=>'B型车','c'=>'C型车');
		$dust_ary=array(1=>'Ⅰ 类料',2=>'Ⅱ 类料',3=>'Ⅲ 类料');
		$_num=0;
		if(!empty($list)){
			$html .= '<tr><td width=”100″ colspan='.$cols_num.' align=center style=\'font-size:14.0pt;font-weight:700;font-family:"Arial Unicode MS", sans-serif;height:25pt\'>挖机装车统计表</td></tr>';
			
			foreach($list as $val){
				$rtn[$val['truck']][$val['dust']]=$val['num'];
			}
		
			foreach($truck_rtn as $k=>$v){
				foreach ($dust_ary as $key=>$vo){
					$_num+=$rtn[$k][$key]?$rtn[$k][$key]:0;
					$html .= '<tr>' ;
					if($key==1)
						$html .= '<td width=”100″ rowspan="3" align=center x:str>'.($v).'</td>' ;
					$html .= '<td width=”100″ align=center x:str><strong>'.($vo).'</strong></td>' ;
					$html .= '<td width=”100″ align=center x:str>'.($rtn[$k][$key]).'</td>' ;
					$html .= '</tr>' ;
				}
			}
			
			$html .= "<tr><td width=”100″ align=center colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;合计：{$_num} 车</td></tr>";			
		}
									
		$html .= '</table></body></html>';
				
		header("Content-type:application/vnd.ms-excel");
		header('Content-Type: application/octet-stream');
		header("Content-Disposition:attachment;filename={$filename}.xls");
		header('Cache-Control: max-age=0');
		exit($html);		
	}
	
	
	//挖机工作时间统计
	function admin_act_boss_report_dustcar($data){
		global $boss_obj;
		
		$list=$boss_obj->get_report_dust($data);		
		if(empty($list)){
			location_msgwap("暂无数据");
		}
		
		$cid=request('cid',false,true);
		$dinfo=$boss_obj->_car_info($cid,'code,carno');
		
		$filename = "SYT_REPORT:".date('YmdHis') ;
		$title_ext = '渣车统计表' ;
		$title = array('挖机号','路线','车数');
		
		$cols_num = count($title);
		$html='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
	    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	    <html>
	    <head>
	    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
	    </head>
	    <body>
	    <table x:str border=1 cellpadding=0 cellspacing=0>';
		
		$html .= '<tr><td width=”100″ colspan='.$cols_num.' align=center style=\'font-size:14.0pt;font-weight:700;font-family:"Arial Unicode MS", sans-serif;height:25pt\'>'.$title_ext.'</td></tr>';
		
		//开始时间		
		if($data['start_time']){
			$html .= "<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;统计期间：{$data['start_time']}&nbsp;&nbsp;&nbsp;&nbsp;编号：{$dinfo['carno']}&nbsp;&nbsp;&nbsp;&nbsp;设备号：{$dinfo['code']}</td></tr>";
		}
		
		$first=$boss_obj->get_report_dust_one($data,1);
		$first_time=date('Y-m-d H:i:s',$first['ctime']);
		$last=$boss_obj->get_report_dust_one($data,2);
		$last_time=date('Y-m-d H:i:s',$last['ctime']);
		$html.="<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;第一车时间：{$first_time}&nbsp;&nbsp;&nbsp;&nbsp;最后一车时间：{$last_time}</td></tr>";		
		
		//导出xls 开始
		if (!empty($title)){
			$html .= '<tr>' ;
			foreach ($title as $k => $v) {
				$html .= '<td width=”100″ align=center style=\'height:25pt;background:silver;\'>'.$v.'</td>' ;
			}
			$html .= '</tr>' ;
		}
		
		
		$_sum=0;
		if($list){					
			foreach($list as $vo){
				$html .= '<tr>' ;
				$html .= '<td width=”100″ align=center x:str><strong>'.($vo['wj_no']).'</strong></td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($vo['line']).'</td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($vo['num']).'</td>' ;
				$html .= '</tr>' ;
				$_sum+=$vo['num'];
			}
		}

		$html.="<tr><td width=”100″ align=center colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;合计：{$_sum} 车</td></tr>";
					
		$html .= '</table></body></html>';
				
		header("Content-type:application/vnd.ms-excel");
		header('Content-Type: application/octet-stream');
		header("Content-Disposition:attachment;filename={$filename}.xls");
		header('Cache-Control: max-age=0');
		exit($html);			
	}	
	
	
	//渣车装车统计表导出
	function admin_act_boss_report_dust(){
		global $boss_obj;
		
		$data = $_GET;
		
		$data['end_time']=$data['start_time'];
		
		//1装车
		$type=3;
		$cols='id,pid,ctime,dname,dno,wj_no,line';
		$list=$boss_obj->get_report_all($data,$type);
		if(empty($list)){
			location_msgwap("暂无数据");
		}
		
		$filename = "SYT_REPORT:".date('YmdHis') ;
		$title_ext = '运输明细统计' ;
		$title = array('项目名称','渣车编号','设备号','装车时间','挖机号','路线');
		
		$cols_num = count($title);
		$html='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
	    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	    <html>
	    <head>
	    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
	    </head>
	    <body>
	    <table x:str border=1 cellpadding=0 cellspacing=0>';
		
		$html .= '<tr><td width=”100″ colspan='.$cols_num.' align=center style=\'font-size:14.0pt;font-weight:700;font-family:"Arial Unicode MS", sans-serif;height:25pt\'>'.$title_ext.'</td></tr>';
		
		//开始时间
		if($data['start_time'] || $data['end_time']){
			$_num=count($list);
			$html .= "<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;统计期间：{$data['start_time']}&nbsp;&nbsp;&nbsp;&nbsp;共计{$_num}车</td></tr>";
		}
		
		//导出xls 开始
		if (!empty($title)){
			$html .= '<tr>' ;
			foreach ($title as $k => $v) {
				$html .= '<td width=”100″ align=center style=\'height:25pt;background:silver;\'>'.$v.'</td>' ;
			}
			$html .= '</tr>' ;
		}
		
		//项目名称
		$project_obj=new project();
		$project_ary=$project_obj->project_all();
		
				
		if(!empty($list)){		
			foreach($list as $key=>$cv){						
				$html .= '<tr>' ;
				$html .= '<td width=”100″ align=right x:str>'.($project_ary[$cv['pid']]).'</td>' ;
				$html .= '<td width=”100″ align=center x:str><strong>'.($cv['dname']).'</strong></td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($cv['dno']).'</td>' ;
				$html .= '<td width=”100″ align=center x:str>'.(date('YmdHis',$cv['ctime'])).'</td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($cv['wj_no']).'</td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($cv['line']).'</td>' ;				
				$html .= '</tr>' ;
			}
		}
		
		$html .= '</table></body></html>';
				
		header("Content-type:application/vnd.ms-excel");
		header('Content-Type: application/octet-stream');
		header("Content-Disposition:attachment;filename={$filename}.xls");
		header('Cache-Control: max-age=0');
		exit($html);		
	}
	
	
	//渣车装车统计表导出
	function admin_act_boss_report_dust_all(){
		global $boss_obj;
	
		$data = $_GET;
	
		$data['end_time']=$data['start_time'];			
		$list=$boss_obj->get_report_total_dust_num($data);
		if(empty($list)){
			location_msgwap("暂无数据");
		}
	
		$filename = "SYT_REPORT:".date('YmdHis') ;
		$title_ext = '运输数量统计' ;
		$title = array('车牌号','挖机号','路线','车数');
	
		$cols_num = count($title);
		$html='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
	    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	    <html>
	    <head>
	    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
	    </head>
	    <body>
	    <table x:str border=1 cellpadding=0 cellspacing=0>';
	
		$html .= '<tr><td width=”100″ colspan='.$cols_num.' align=center style=\'font-size:14.0pt;font-weight:700;font-family:"Arial Unicode MS", sans-serif;height:25pt\'>'.$title_ext.'</td></tr>';
	
		//开始时间
		if($data['start_time'] || $data['end_time']){			
			$html .= "<tr><td width=”100″ colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;统计期间：{$data['start_time']}&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>";
		}
	
		//导出xls 开始
		if (!empty($title)){
			$html .= '<tr>' ;
			foreach ($title as $k => $v) {
				$html .= '<td width=”100″ align=center style=\'height:25pt;background:silver;\'>'.$v.'</td>' ;
			}
			$html .= '</tr>' ;
		}
	
	
		$_sum=0;
		if(!empty($list)){
			foreach($list as $key=>$cv){
				$html .= '<tr>' ;
				$html .= '<td width=”100″ align=center x:str><strong>'.($cv['dname']).'</strong></td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($cv['wj_no']).'</td>' ;				
				$html .= '<td width=”100″ align=center x:str>'.($cv['line']).'</td>' ;
				$html .= '<td width=”100″ align=center x:str>'.($cv['num']).'</td>' ;
				$html .= '</tr>' ;
				$_sum+=$cv['num'];
			}
		}
	
		$html .= "<tr><td width=”100″ align=center colspan='{$cols_num}'>&nbsp;&nbsp;&nbsp;&nbsp;合计：{$_sum}&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>";
		
		$html .= '</table></body></html>';
	
		header("Content-type:application/vnd.ms-excel");
		header('Content-Type: application/octet-stream');
		header("Content-Disposition:attachment;filename={$filename}.xls");
		header('Cache-Control: max-age=0');
		exit($html);
	}	
	
	
    //function
    //*+------------------------------------------------------------------------+*/

	
	
?>
